package com.xing.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xing.DTO.SysUserDTO;
import com.xing.entity.SysUserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/12/3 21:47
 */
@Mapper
public interface SysUserDao extends BaseMapper<SysUserEntity> {

    @Select("select distinct su.id,\n" +
            "                su.username,\n" +
            "                su.password,\n" +
            "                su.gender,\n" +
            "                su.create_date,\n" +
            "                su.note,\n" +
            "                su.nickname,\n" +
            "                so.url,\n" +
            "                count(distinct la.id)  as fans,\n" +
            "                count(distinct lat.id) as attention,\n" +
            "                IF(sr.name='admin'||sr.name='live', 1, 0) is_anchor\n" +
            "from sys_user su\n" +
            "         left join sys_oss as so on su.head_url = so.id\n" +
            "         left join live_attention as la on su.id = la.attentioned_id\n" +
            "         left join live_attention as lat on su.id = lat.attention_id\n" +
            "LEFT JOIN sys_user_role sur ON sur.user_id = su.id\n" +
            "         LEFT JOIN sys_role sr ON sr.id = sur.role_id\n" +
            "where su.id = #{id}\n" +
            "  and su.del_flag = 0\n" +
            "GROUP BY sr.name;")
    SysUserDTO selectUserById(@Param("id") String id);


    @Select("SELECT url FROM  sys_oss WHERE id = #{id}")
    String GetheadUrl(@Param("id") Long id);

    @Select("SELECT id FROM sys_user WHERE status = 0 AND del_flag = 0")
    List<Long> getAllUserId();
}
